<?php 
require_once ('Zend/Controller/Router/Interface.php');
require_once ('Zend/Controller/Router/Abstract.php');

/**
 * A Zend application router that parses commandline requests rather than HTTP requests. The
 * format for these request is -m (module) -c (controller) -a (action).
 * 
 * @author Michael Krotscheck
 */
class Core_Controller_Router_Cli
	extends Zend_Controller_Router_Abstract
	implements Zend_Controller_Router_Interface
{
	/**
	 * Method implemented for interface purposes only.
	 * 
	 * @see Zend_Controller_Router_Interface::assemble()
	 */
	public function assemble($userParams, $name = null, $reset = false, $encode = true)
	{
        echo "Not implemented\n", exit;
	}
	
	/**
	 * Router. Pulls commandline options and sets the appropriate actions and defaults on the 
	 * dispatcher.
	 * 
	 * @see Zend_Controller_Router_Interface::route()
	 */
	public function route(Zend_Controller_Request_Abstract $dispatcher)
	{
	    $opts = new Zend_Console_Getopt( array(
	    					'module|m=s' => 'Module',
	    					'controller|c=s' => 'Controller',
	    					'action|a=s' => 'The action to execute'
	    				) );
	
		if ( !empty($opts->module))
		{
			$dispatcher->setModuleName($opts->module);
		}
		else
		{
			$dispatcher->setModuleName('default');
		}
		
		if ( isset($opts->controller))
		{
			$dispatcher->setControllerName($opts->controller);
		}
		else
		{
			$dispatcher->setControllerName('index');
		}
		
		if ( !empty($opts->action))
		{
			$dispatcher->setActionName($opts->action);
		}
		else
		{
			$dispatcher->setActionName('index');
		}
		
	}
}
